package 昆明理工大学;

import com.alibaba.excel.EasyExcel;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import 武汉大学.WhuBean;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class KMu {
    public static void main(String[] args) throws IOException {
        String Url = "https://pwee.kmust.edu.cn/szdw/dsjj/1.htm";
        String substring = null;
        KMuBean kMuBean = null;
        List<KMuBean> kMuBeans = new ArrayList<>();
        Connection connect = Jsoup.connect(Url);
        Document post = connect.post();
//        for (Element pNextPFun : post.getElementsByClass("p_next p_fun")) {
//            Element element = pNextPFun.getElementsByTag("a").get(0);
//            System.out.println(element.attr("href"));
//            Connection connect1 = Jsoup.connect("https://pwee.kmust.edu.cn/szdw/" + element.attr("href"));
//
//        }

        for (Element element : post.getElementsByClass("list_main_content")) {
//            System.out.println(element.text());
            for (Element li : element.getElementsByTag("li")) {
                kMuBean = new KMuBean();
                Element element1 = li.getElementsByTag("a").get(1);
                kMuBean.setT_name(element1.text());
//                System.out.println(element1.text());
                String attr = element1.attr("href");
                substring = attr.substring(6, attr.length());
                Connection connect1 = Jsoup.connect("https://pwee.kmust.edu.cn/" + substring);
                Document post1 = connect1.post();
                for (Element table : post1.getElementsByTag("table")) {
//                    System.out.println(table.text());
                    kMuBean.setInfo(table.text());
                }
                kMuBeans.add(kMuBean);
            }

        }
        EasyExcel.write("src/KMu3.xlsx", KMuBean.class).sheet("user").doWrite(kMuBeans);

    }



}
